Importing the libraries
library(tidyverse)
library(plotly)
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
Importing the data-set
# National Parks in California
ca = read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/ca.csv")
Rows: 789 Columns: 7
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(ca)
# Acadia National Park
acadia <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/acadia.csv")
Rows: 98 Columns: 7
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(acadia)
# Southeast US National Parks
se <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/se.csv")
Rows: 453 Columns: 7
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(se)
# 2016 Visitation for all Pacific West National Parks
visit_16 <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/visit_16.csv")
Rows: 17 Columns: 7
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(visit_16)
# All Nationally designated sites in Massachusetts
mass <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/mass.csv")
Rows: 13 Columns: 7
── Column specification ───────────────────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(mass)
ggplot
scatter_plot = plot_ly(data=ca, x=~year, y=~visitors,color = ~park_name, type='scatter',mode='markers') %>%
layout(
title= list(text = "<b>Body weight vs Brain weight"),
legend = list(title = list(text ='<b>Animals')),
xaxis = list(title = list(text ='<b>Brain Weight')),
yaxis = list(title = list(text ='<b>Body Weight')))
scatter_plot
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
LS0tCnRpdGxlOiAiUiBOb3RlYm9vayIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKIyMgSW1wb3J0aW5nIHRoZSBsaWJyYXJpZXMKYGBge3J9CmxpYnJhcnkodGlkeXZlcnNlKQpsaWJyYXJ5KHBsb3RseSkKYGBgCgojIyBJbXBvcnRpbmcgdGhlIGRhdGEtc2V0CmBgYHtyfQojIE5hdGlvbmFsIFBhcmtzIGluIENhbGlmb3JuaWEKY2EgPSByZWFkX2NzdigiaHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29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